package com.hj.ct.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.hj.ct.model.SetAlarm;

public class SetAlarmUtil {
	public static float getWarnDust(SetAlarm alarm) {
		long currentTime = System.currentTimeMillis();
		long nightTime = changeTime(alarm.getNightTimeStart());
		long dayTime = changeTime(alarm.getDayTimeStart());
		if (currentTime >= nightTime) {
			return alarm.getDustHi_Night();
		} else if (currentTime >= dayTime) {
			return alarm.getDustHi_Day();
		} else if (currentTime < dayTime) {
			return alarm.getDustHi_Night();
		} else {
			return alarm.getDustHi_Night();
		}
	}

	public static float getWarnNoise(SetAlarm alarm) {
		long currentTime = System.currentTimeMillis();
		long nightTime = changeTime(alarm.getNightTimeStart());
		long dayTime = changeTime(alarm.getDayTimeStart());
		if (currentTime >= nightTime) {
			return alarm.getNoiseHi_Night();
		} else if (currentTime >= dayTime) {
			return alarm.getNoiseHi_Day();
		} else if (currentTime < dayTime) {
			return alarm.getNoiseHi_Night();
		} else {
			return alarm.getNoiseHi_Night();
		}
	}

	public static long changeTime(String h_m_s) {
		return fmtStrToDate(fmtDateToYMD(new Date())+" "+h_m_s, "yyyy-MM-dd HH:mm:ss").getTime();
	}

	public static Date fmtStrToDate(String date, String dtFormat) {
		try {
			SimpleDateFormat dateFormat = new SimpleDateFormat(dtFormat);
			return dateFormat.parse(date);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	public static String fmtDateToYMD(Date date) {
		return fmtDateToStr(date, "yyyy-MM-dd");
	}
	
	public static String fmtDateToStr(Date date, String dtFormat) {  
	     if (date == null)  
	         return "";  
	     try {  
	         SimpleDateFormat dateFormat = new SimpleDateFormat(dtFormat);  
	         return dateFormat.format(date);  
	     } catch (Exception e) {  
	         e.printStackTrace();  
	         return "";  
	     }  
	}
	public static String getDustType(String type){
		String typeStr = type+"";
		if("0".equals(type)){
			typeStr = "实时值";
		}else if("1".equals(type)){
			typeStr = "小时均值";
		}
		return typeStr;
	}
	
	public static String getNoiseType(String type){
		String typeStr = type+"";
		if("0".equals(type)){
			typeStr = "LAFRealTime";
		}else if("1".equals(type)){
			typeStr = "LAFMaxPrf";
		}else if("2".equals(type)){
			typeStr = "LAeqPrf";
		}else if("3".equals(type)){
			typeStr = "LCpeakPrf";
		}else if("4".equals(type)){
			typeStr = "LAMaxPer";
		}else if("5".equals(type)){
			typeStr = "LAwqPer";
		}else if("6".equals(type)){
			typeStr = "LAF10Per";
		}else if("7".equals(type)){
			typeStr = "LAF90Per";
		}else if("8".equals(type)){
			typeStr = "LAF95Per";
		}
		return typeStr;
	}
	
	
}
